package handler;

import context.ComServerContext;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import message.Message;
import message.StringMessage;

/**
 * @author wb_zhulinzhong
 * @date 2021-04-15 11:43:22
 */
public class ComServerReplyChannelHandler extends SimpleChannelInboundHandler<Message> {


    @Override
    protected void messageReceived(ChannelHandlerContext ctx, Message msg) throws Exception {

    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        sendConnectSuccessMessage(ctx.channel().id().asShortText());
        super.channelActive(ctx);
    }

    private void sendConnectSuccessMessage(String channelId){
        StringMessage stringMessage = new StringMessage("server", "连接成功，客户端ID：" + channelId);
        ComServerContext.comContext().serverSendMessageToClientByClientId(stringMessage, channelId);
    }
}
